package com.gitee.ed.arithmetic.leetcode.question.question_1_100.question_1_10;

import com.gitee.ed.arithmetic.leetcode.SolutionRunner;
import com.gitee.ed.arithmetic.leetcode.common.Question;
import com.gitee.ed.arithmetic.leetcode.solution.solution_1_100.solution_1_10.Solution6;

/**
 * @author hongda.li
 */
public class Question6 implements Question<Solution6> {
    @Override
    public String link() {
        return "https://leetcode.cn/problems/zigzag-conversion/description/";
    }

    @Override
    public String title() {
        return "6.Z字形变换";
    }

    @Override
    public String description() {
        return """
                将一个给定字符串 s 根据给定的行数 numRows ，以从上往下、从左到右进行 Z 字形排列。
                比如输入字符串为 "PAYPALISHIRING" 行数为 3 时，排列如下：
                P   A   H   N
                A P L S I I G
                Y   I   R
                之后，你的输出需要从左往右逐行读取，产生出一个新的字符串，比如："PAHNAPLSIIGYIR"。
                请你实现这个将字符串进行指定行数变换的函数：
                string convert(string s, int numRows);
                """;
    }

    @Override
    public void test(Solution6 solution) {
        this.test1(solution);

        this.test2(solution);

        this.test3(solution);
    }

    private void test1(Solution6 solution) {
        String s = "PAYPALISHIRING";
        int num = 3;
        String expect = "PAHNAPLSIIGYIR";
        String actual = solution.convert(s, num);
        SolutionRunner.checkString(expect, actual);
    }

    private void test2(Solution6 solution) {
        String s = "PAYPALISHIRING";
        int num = 4;
        String expect = "PINALSIGYAHRPI";
        String actual = solution.convert(s, num);
        SolutionRunner.checkString(expect, actual);
    }

    private void test3(Solution6 solution) {
        String s = "A";
        int num = 1;
        String expect = "A";
        String actual = solution.convert(s, num);
        SolutionRunner.checkString(expect, actual);
    }
}
